using ServiceStack.Logging;
using System;
using System.Collections.Generic;
namespace ServiceStack
{
	public static class DisposableExtensions
	{
		public static void Dispose(this IEnumerable<IDisposable> resources, ILog log)
		{
			foreach (IDisposable current in resources)
			{
				if (current != null)
				{
					try
					{
						current.Dispose();
					}
					catch (Exception exception)
					{
						if (log != null)
						{
							log.Error(string.Format("Error disposing of '{0}'", current.GetType().FullName), exception);
						}
					}
				}
			}
		}
		public static void Dispose(this IEnumerable<IDisposable> resources)
		{
			resources.Dispose(null);
		}
		public static void Dispose(params IDisposable[] disposables)
		{
			disposables.Dispose(null);
		}
		public static void Run<T>(this T disposable, Action<T> runActionThenDispose) where T : IDisposable
		{
			using (disposable)
			{
				runActionThenDispose(disposable);
			}
		}
	}
}
